package cn.com.zsw.gblog.modules.gblog.controller;

import cn.com.zsw.gblog.modules.gblog.dto.CommentSubmitDTO;
import cn.com.zsw.gblog.modules.common.contrller.BaseController;
import cn.com.zsw.gblog.modules.gblog.service.GbCommentService;
import cn.com.zsw.gblog.modules.gblog.vo.CommentsPageVO;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * (GbComment)表控制层
 *
 * @author shiwangzhou
 * @since 2020-06-22 16:26:14
 */
@RestController
@RequestMapping("blog/comments")
@Api(tags = "评论", value = "GbCommentController")
@Slf4j
public class GbCommentController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private GbCommentService gbCommentService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    /**
     * @Author: shiwangZhou
     * @Description: 获取博客下的评论
     * @Date: 2020-06-22 16:36
     * @Return cn.com.zsw.gblog.entity.GbComment
     * @Param id
     */
    @GetMapping("list")
    @ApiOperation(value = "获取博客下的评论")
    public R<List<CommentsPageVO>> selectOne(String postId) {
        return R.ok(gbCommentService.selectListPage(postId));
    }

    @PostMapping("reply/submit")
    @ApiOperation(value = "提交评论")
    public R submitReply(@Valid @RequestBody CommentSubmitDTO commentSubmitDTO) {
        return R.ok(gbCommentService.submitReply(commentSubmitDTO));
    }


}